// EMERGENT GAME TECHNOLOGIES PROPRIETARY INFORMATION
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Emergent Game Technologies and may not 
// be copied or disclosed except in accordance with the terms of that 
// agreement.
//
//      Copyright (c) 1996-2007 Emergent Game Technologies.
//      All Rights Reserved.
//
// Emergent Game Technologies, Chapel Hill, North Carolina 27517
// http://www.emergent.net

#include "CEGUIGamebryoTexture.h"
#include "CEGUIGamebryoRenderer.h"
#include "CEGUIExceptions.h"
#include "CEGUISystem.h"

#include "CEGUIDefaultResourceProvider.h"

#include <NiRenderer.h>

//---------------------------------------------------------------------------
CEGUIGamebryoTexture::CEGUIGamebryoTexture(Renderer* owner) :
	Texture(owner), m_spGamebryoTexture(0)
{
}
//---------------------------------------------------------------------------
CEGUIGamebryoTexture::~CEGUIGamebryoTexture(void)
{
}
//---------------------------------------------------------------------------
void CEGUIGamebryoTexture::loadFromFile(const String& filename, 
                                        const String& resourceGroup)
{	
	ResourceProvider *pkRes = System::getSingleton().getResourceProvider();
	DefaultResourceProvider *pkDefaultRes = (DefaultResourceProvider*)pkRes;

    // CEGUI::DefaultResourceProvider::getFinalFilename is unfortunately
    // protected by default, so the next line cannot be used without
    // modifications. For this sample, I left CEGUI unmodified for your
    // convenience, and just hardcoded the known path to the images.
    // String final_filename(getFinalFilename(filename, resourceGroup);
    char pcFinalFilename[255] = "../../data/imagesets/";
	NiStrcat(pcFinalFilename, 255, filename.c_str());

	m_spGamebryoTexture = NiSourceTexture::Create(pcFinalFilename);
}
//---------------------------------------------------------------------------
void CEGUIGamebryoTexture::loadFromMemory(const void* buffPtr, 
	uint buffWidth, uint buffHeight, Texture::PixelFormat pixFormat)
{
	NiPixelFormat kDesc(NiPixelFormat::FORMAT_RGBA,
		NiPixelFormat::COMP_RED,NiPixelFormat::REP_NORM_INT,8,
		NiPixelFormat::COMP_GREEN,NiPixelFormat::REP_NORM_INT,8,
		NiPixelFormat::COMP_BLUE,NiPixelFormat::REP_NORM_INT,8,
		NiPixelFormat::COMP_ALPHA,NiPixelFormat::REP_NORM_INT,8);

	NiPixelData *pkData = NiNew NiPixelData(buffWidth, buffHeight, kDesc);
	memcpy(pkData->GetPixels(), buffPtr, buffWidth * buffHeight * 4);
	m_spGamebryoTexture = NiSourceTexture::Create(pkData);
}
//---------------------------------------------------------------------------

